<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="5" :sm="24">
              <a-form-item label>
                <a-input-search v-model="queryParam.memberId" placeholder="请输入角色名称/代码" />
              </a-form-item>
            </a-col>

            <a-col :md="(!advanced && 10) || 24" :sm="24">
              <span>
                <a-button type="primary" icon="search" @click="loadDataRefresh()">查询</a-button>
              </span>
            </a-col>

            <a-col :md="(!advanced && 9) || 24" :sm="24" style="text-align: right;">
              <span>
                <a-button type="primary" icon="plus" @click="loadDataRefresh()">新增</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import moment from 'moment'
import { STable, Ellipsis } from '@/components'

import { putAction, postAction, getAction } from '@/api/manage'
const columns = [
  {
    title: '序号',
    align: 'center',
    width: '80px',
    dataIndex: 'member.id',
  },
  {
    title: '角色代码',
    dataIndex: 'createTime',
    width: '180px',
    align: 'center',
  },
  {
    title: '角色名',
    dataIndex: 'email',
    width: '180px',
    align: 'center',
  },
  {
    title: '描述',
    dataIndex: 'address',
    ellipsis: true,
    width: '250px',
    align: 'center',
  },
  {
    title: '是否启用',
    dataIndex: 'amount',
    align: 'center',
    width: '100px',
  },
  {
    title: '创建时间',
    align: 'center',
    dataIndex: 'updateTime',
    width: '200px',
  },

  {
    title: '操作',
    dataIndex: 'action',
    width: '250px',
    align: 'center',
    scopedSlots: { customRender: 'action' },
  },
]

export default {
  name: 'TableList',
  components: {
    STable,
    Ellipsis,
  },
  data() {
    this.columns = columns
    return {
      visible: false,
      confirmLoading: false,
      mdl: null,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: { keywords: '', certifiedBusinessStatus: '', startTime: '', endTime: '', memberId: '' },
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({ sort: 'createTime,desc' }, parameter, this.queryParam)
        console.log('loadData request parameters:', requestParameters)
        return getAction('/api/businessAuthApply', requestParameters).then((res) => {
          return {
            ...requestParameters,
            totalCount: res.result.totalElements,
            totalPage: 10,
            data: res.result.content,
          }
        })
      },
      selectedRowKeys: [],
      selectedRows: [],
    }
  },

  computed: {
    rowSelection() {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange,
      }
    },
  },
  filters: {
    statusFilter(type) {
      return statusMap[type].text
    },
    statusTypeFilter(type) {
      return statusMap[type].status
    },
  },
  methods: {
    handleChange(value) {
      // this.queryParam.clientType = value
      console.log(this.queryParam.clientType)
      this.loadDataRefresh()
    },

    lookLink(record) {
      console.log(record)
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    loadDataRefresh() {
      this.$refs.table.refresh() // refresh() 不传参默认值 false 不刷新到分页第一页
    },
  },
}
</script>
